package Chinese.Education.Identify.service;

import Chinese.Education.Identify.mapper.MajorMapper;
import Chinese.Education.Identify.pojo.Major;
import Chinese.Education.Identify.pojo.Student;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service
public class MajorService {
    @Resource
    private MajorMapper majorMapper;

    public Map<String, Object> selectMajor(int page, int limit, String majorName)
    {
        int offset = (page - 1) * limit;
        List<Major> list = majorMapper.selectMajor(offset, limit,majorName);
        int count = majorMapper.selectCount();
        Map<String, Object> major = new HashMap<>();
        major.put("code", 0);
        major.put("msg", "");
        major.put("count", count);
        major.put("data", list);
        return major;
    }

    public Map<String, Object> deleteMajor(String majorName)
    {
       majorMapper.deleteMajor(majorName);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "删除成功");
        map.put("data", majorName);
        return map;
    }

    public Map<String, Object> insertMajor(Major major)
    {
        majorMapper.insertMajor(major);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "添加成功");
        map.put("data", major);
        return map;
    }

    public Map<String, Object> updateMajor(Major major)
    {
        majorMapper.updateMajor(major);
        Map<String, Object> map = new HashMap<>();
        map.put("code", 200);
        map.put("msg", "修改成功");
        map.put("data", major);
        return map;
    }
}
